import type * as T from './type'
import http from '@/utils/http'

export type * from './type'

/**
 * 账号登录
 * @param req
 */
export function accountLogin(req: T.AccountLoginReq) {
  return http.post<T.LoginResp>(`/auth/login/account`, req)
}

/**
 * 手机号登录
 * @param req
 */
export function phoneLogin(req: T.PhoneLoginReq) {
  return http.post<T.LoginResp>(`/auth/login/phone`, req)
}

/**
 * 邮箱登录
 * @param req
 */
export function emailLogin(req: T.EmailLoginReq) {
  return http.post<T.LoginResp>(`/auth/login/email`, req)
}

/**
 * 三方账号登录
 * @param source
 * @param req
 */
export function thirdpartyLogin(source: string, req: any) {
  return http.post<T.LoginResp>(`/oauth/${source}`, req)
}

/**
 * 三方账号登录授权
 * @param source
 */
export function thirdpartyAuth(source: string) {
  return http.get<T.ThirdpartyAuthAuthorizeResp>(`/oauth/${source}`)
}

/**
 * 退出登录
 */
export function logout() {
  return http.post(`/auth/logout`)
}

/**
 * 获取用户信息
 */
export const getUserInfo = () => {
  return http.get<T.UserInfo>(`/auth/user/info`)
}

/**
 * 获取路由信息
 */
export const getUserRoute = () => {
  return http.get<T.RouteItem[]>(`/auth/user/route`)
}
